package com.smyk.btchina.view.main

import androidx.fragment.app.Fragment
import com.smyk.btchina.R
import com.smyk.btchina.adapter.MyPagerFragmentAdapter
import com.smyk.btchina.base.BaseMvvmActivity
import com.smyk.btchina.databinding.ActivityMainBinding
import com.smyk.btchina.view.main.fragment.FastFragment
import com.smyk.btchina.view.main.fragment.FindFragment
import com.smyk.btchina.view.main.fragment.HomeFragment
import com.smyk.btchina.view.main.fragment.MineFragment
import com.smyk.btchina.view_model.MainViewModel

/**
 * @des 主页
 * @date 2021/9/7
 * @author sam
 */
class MainActivity : BaseMvvmActivity<ActivityMainBinding, MainViewModel>() {

    private val mHomeFragment by lazy { HomeFragment() }
    private val mFastFragment by lazy { FastFragment() }
    private val mFindFragment by lazy { FindFragment() }
    private val mMineFragment by lazy { MineFragment() }
    private val mFragments by lazy { ArrayList<Fragment>() }

    override fun getViewModel(): MainViewModel = MainViewModel()

    override fun getViewBing(): ActivityMainBinding = ActivityMainBinding.inflate(layoutInflater)

    override fun initView() {
        mFragments.apply {
            add(mHomeFragment)
            add(mFastFragment)
            add(mFindFragment)
            add(mMineFragment)
        }
        mBinding.vpMain.let {
            it.adapter = MyPagerFragmentAdapter(supportFragmentManager, mFragments)
            it.currentItem = 0
            it.offscreenPageLimit = 4
        }
        mBinding.rgMain.setOnCheckedChangeListener { _, checkedId ->
            when (checkedId) {
                R.id.rb_main_1 -> {
                    mBinding.vpMain.setCurrentItem(0, false)
                }
                R.id.rb_main_2 -> {
                    mBinding.vpMain.setCurrentItem(1, false)
                }
                R.id.rb_main_3 -> {
                    mBinding.vpMain.setCurrentItem(2, false)
                }
                R.id.rb_main_4 -> {
                    mBinding.vpMain.setCurrentItem(3, false)
                }
                else -> {

                }
            }
        }
    }
}